<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Elenco alunni</title>
<link href="../../css/main.css" rel="stylesheet" />
<link href="../../css/themes/default.css" rel="stylesheet" type="text/css"/>
<link href="../../css/themes/mac_os_x.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../js/prototype.js"></script>
<script type="text/javascript" src="../../js/scriptaculous.js"></script>
<script type="text/javascript" src="../../js/controls.js"></script>
<script type="text/javascript" src="../../js/page.js"></script>
<script type="text/javascript" src="../../js/window.js"></script>
<script type="text/javascript" src="../../js/window_effects.js"></script>
<script type="text/javascript">
function upd_cls(sel, student, row){
	var url = "update_class.php";
    //var data = "cls="+classe+"&mat="+materia+"&doc="+doc;
    var req = new Ajax.Request(url,
			  {
			    	method:'post',
			    	parameters: {cls: sel.value, stud_id: student},
			    	onSuccess: function(transport){
			    		var response = transport.responseText || "no response text";
				    	//alert(response);
			    		dati = response.split(";");
			    		if(dati[0] == "ok"){
							//alert(dati[1]);
							//document.location.href = "alunni.php?id_classe=<?php print $_REQUEST['id_classe'] ?>";
							location.reload();
							//document.getElementById("tr_"+row).style.display = "none";
			            }
			            else{
			                alert("Aggiornamento non riuscito. Query: "+dati[1]+"\nErrore: "+dati[2]);
			                return;
			            }
			    	},
			    	onFailure: function(){ alert("Si e' verificato un errore..."); }
			  });
}
</script>
</head>
<body>
    <div id="header">
		<div class="wrap">
			<?php include "../header.php" ?>
		</div>
	</div>
	<div class="wrap">
	<div id="main" style="background-color: #FFFFFF; padding-bottom: 30px; width: 100%">
        <form method="post">
        <table class="admin_table">
            <tr class="admin_title_row">
                <td colspan="3" style="font-weight: bold; padding-top: 20px" align="center">Elenco alunni classe <?php print $desc ?> (<?php print $res_alunni->num_rows ?>)</td>
            </tr>
            <tr>
            	<td style="padding-left: 2px; width: 5%" class="adm_titolo_elenco"></td>
                <td style="padding-left: 2px; width: 75%" class="adm_titolo_elenco">Alunno</td>
                <td style="padding-left: 10px; width: 20%" class="adm_titolo_elenco">Classe</td>
            </tr>
            <tr class="admin_row">
                <td colspan="2"></td>
            </tr>
            <?php
            $x = 1;
            while($stud = $res_alunni->fetch_assoc()){
                
            ?>
            <tr class="admin_row<?php if($x % 2) print(" odd") ?>">
            	<td style="padding-right: 12px; color: #003366; text-align: right"><?php print $x ?>.</td>
                <td style="padding-left: 2px; color: #003366; text-align: left"><?php print $stud['cognome']." ".$stud['nome'] ?></td>
                <td style="color: #003366;">
                <select name="cls" id="cls" style="width: 95%; font-size: 11px; border: 1px solid" onchange="upd_cls(this, <?php print $stud['id_alunno'] ?>, <?php print $x ?>, '<?php print $stud['classe'] ?>')">
                <?php
                $res_classi->data_seek(0);
                while($_class = $res_classi->fetch_assoc()){
                ?>
                	<option value="<?php print $_class['id_classe'] ?>" <?php if($_class['id_classe'] == $_REQUEST['id_classe']) print("selected") ?> ><?php print $_class['classe'] ?></option>
                <?php 
                }
                ?>
                </select>
                </td>
            </tr>
            <?php
            	$x++;
            }
            ?>
            <tr class="admin_row">
                <td colspan="3"></td>
            </tr>
            <tr class="admin_row admin_menu">
                <td colspan="3">
                    <a href="classi.php">Torna all'elenco classi</a>
                </td>
            </tr>
            <tr class="admin_row">
                <td colspan="3"></td>
            </tr>
        </table>
        </form>
        </div>
        <div id="footer">
			<p>Design: Luka Cvrk - <a href="http://www.solucija.com" title="Free Web Templates">Solucija</a></p>
		</div>
	</div>
</body>
</html>